package com.linkage.educloud.ah.config;

import android.content.Context;
import android.content.SharedPreferences;

import com.yanzhenjie.nohttp.tools.IOUtils;
import com.zzhou.common.library.App;
import com.zzhou.common.library.util.FileUtils;
import com.zzhou.common.library.util.LogUtils;

import java.io.File;

/**
 * Created by 周振 on 2017/4/13.
 */

public class AppConfig {

    private static AppConfig appConfig;

    private SharedPreferences preferences;


    /**
     * App根目录.
     */
    public String APP_PATH_ROOT;

    private AppConfig() {
        preferences = App.INSTANCE.getSharedPreferences("Anhui_Edu", Context.MODE_PRIVATE);

        APP_PATH_ROOT = FileUtils.getRootPath().getAbsolutePath() + File.separator +
                "Anhui_Edu/";
    }

    public static AppConfig getInstance() {
        if (appConfig == null)
            synchronized (AppConfig.class) {
                if (appConfig == null)
                    appConfig = new AppConfig();
            }
        return appConfig;
    }

    public void initialize() {
        boolean iscreate = IOUtils.createFolder(APP_PATH_ROOT);
        LogUtils.e("initialize "+iscreate);
    }

    public void putInt(String key, int value) {
        preferences.edit().putInt(key, value).commit();
    }

    public int getInt(String key, int defValue) {
        return preferences.getInt(key, defValue);
    }

    public void putString(String key, String value) {
        preferences.edit().putString(key, value).commit();
    }

    public String getString(String key, String defValue) {
        return preferences.getString(key, defValue);
    }

    public void putBoolean(String key, boolean value) {
        preferences.edit().putBoolean(key, value).commit();
    }

    public boolean getBoolean(String key, boolean defValue) {
        return preferences.getBoolean(key, defValue);
    }

    public void putLong(String key, long value) {
        preferences.edit().putLong(key, value).commit();
    }

    public long getLong(String key, long defValue) {
        return preferences.getLong(key, defValue);
    }

    public void putFloat(String key, float value) {
        preferences.edit().putFloat(key, value).commit();
    }

    public float getFloat(String key, float defValue) {
        return preferences.getFloat(key, defValue);
    }
    public void remove(String key){
        preferences.edit().remove(key).commit();
    }
    public interface ShareKey{
        String KEY_GUIDE = "key_guide";
        String KEY_DEFAULT_SPLASH = "key_splash";
        String KEY_SHORTDN_CLAZZS = "key_shortdn_clazzs";//用户开通班级网的班级id  多个用“,”分割
        String KEY_HAS_SHORTDN = "key_has_shortdn";//用户班级网状态
    }
}

